<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/base/jsp/include.jsp"%>
<script type="text/javascript">
	var code = '${code}';
	var grid;
	var addFun = function() {
		var rows = grid.datagrid('getSelections');
		var dialog = parent.sy.modalDialog({
			title : '添加成员',
			width : 500,
			height : 400,
			url : sy.contextPath + '/go.do?path=chat/userEdit&deptNo='+code,
			buttons : [ {
				text : '确定',
				handler : function() {
					dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
				}
			} ]
		});
	};
	var delFun = function(id) {
		var rows = grid.datagrid('getSelections');
		if (rows.length == 0) {
			parent.$.messager.w('请选择需要删除的记录！');
			return;
		}
		parent.$.messager.confirm('询问', '您确定要删除此记录？', function(r) {
			if (r) {
				var ids = [];
				for ( var i = 0, l = rows.length; i < l; i++) {
					var r = rows[i];
					ids.push(r.chatId);
				}
				var id = ids.join(',');
				
				$.post(sy.contextPath + '/chatDeptUser/del', {
					id : id
				}, function() {
					grid.datagrid('reload');
				}, 'json');
			}
		});
	};
	var editFun = function(){
		var rows = grid.datagrid('getSelections');
		if (rows.length != 1) {
			parent.$.messager.alert('请选择一条记录进行编辑！');
			return;
		}
		var dialog = parent.sy.modalDialog({
			title : '编辑',
			width : 500,
			height : 400,
			url : sy.contextPath + '/go.do?path=chat/userEdit&id=' + rows[0].chatId,
			buttons : [ {
				text : '确定',
				handler : function() {
					dialog.find('iframe').get(0).contentWindow.submitForm(dialog, grid, parent.$);
				}
			} ]
		});
	}
	
	
	
	$(function() {
		grid = $('#grid').datagrid({
			url : sy.contextPath + '/chatDeptUser/list?code='+code,
			toolbar : '#toolbar',
			pagination : true,
			columns : [ [{
				width : $(this).width() * 0.1,
				title : '姓名',
				align : 'center',
				field : 'nickName'
			},{
				width : $(this).width() * 0.05,
				title : '头像',
				align : 'center',
				field : 'headImg',
				formatter:function(v){
					return po.showImg(v,18,18);
				}
			},{
				width : $(this).width() * 0.1,
				title : '部门(企业名称)',
				field : 'deptName',
				align : 'center',
				formatter:function(v,r){
					return r.type == 1? v: r.firmName;
				}
			},{
				width : $(this).width() * 0.1,
				title : '职位',
				field : 'job',
				align : 'center',
				formatter:function(v,r){
					return r.type == 1? v:'';
				}
			},{
				width : $(this).width() * 0.1,
				title : '类型',
				field : 'type',
				align : 'center',
				formatter:function(v,r){
					return r.type == 1?'内部用户':'企业用户';
				}
			}
			, {
				width : $(this).width() * 0.05,
				title : '排序',
				field : 'sortOrder',
				align : 'center'
			}
			]]
		});
		
	});
</script>
</head>
<body class="easyui-layout" data-options="fit:true,border:false">
	<div id="toolbar" style="display: none;">
		<table>
			<!-- <tr>
				<td>
					<form id="searchForm">
						<table>
							<tr>
								<td>名称:</td>
								<td><input name="name" class="easyui-textbox" style="width: 200px;" /></td>
								<td>
									<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.datagrid('load',sy.serializeObject($('#searchForm')));">过滤</a>
									<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a>
								</td>
							</tr>
						</table>
					</form>
				</td>
			</tr> -->
			<tr>
				<td>
					<table>
						<tr>
							<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-note_add',plain:true" onclick="addFun();">添加</a></td>
							<td><div class="datagrid-btn-separator"></div></td>
							<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-table_edit',plain:true" onclick="editFun();">修改</a></td>
							<td><div class="datagrid-btn-separator"></div></td>
							<td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-table_delete',plain:true" onclick="delFun();">删除</a></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</div>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid" data-options="fit:true,border:false"></table>
	</div>
</body>
</html>